package com.cloudservice.ccs.biz.impl;

import com.cloudservice.ccs.biz.IWorkQualityStatisticsBiz;
import com.cloudservice.ccs.entity.WorkQualityStatistics;
import com.cloudservice.ccs.exception.WorkQualityStatisticsException;
import com.cloudservice.ccs.mapper.WorkQualityStatisticsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WorkQualityStatisticsImpl implements IWorkQualityStatisticsBiz {
    @Autowired
    private WorkQualityStatisticsMapper workQualityStatisticsMapper;

    @Override
    public void save(WorkQualityStatistics workQualityStatistics) {
        int res = workQualityStatisticsMapper.save(workQualityStatistics);
        if (res == 0) {
            throw new WorkQualityStatisticsException("Create WorkQualityStatistics failed");
        }
    }

    @Override
    public void update(Integer id, WorkQualityStatistics workQualityStatistics) {
        int res = workQualityStatisticsMapper.update(id, workQualityStatistics);
        if (res == 0) {
            throw new WorkQualityStatisticsException("Update WorkQualityStatistics failed");
        }
    }

    @Override
    public void partialUpdate(Integer id, Map<String, Object> fields) {
        int res = workQualityStatisticsMapper.partialUpdate(id, fields);
        if (res == 0) {
            throw new WorkQualityStatisticsException("Partial update WorkQualityStatistics failed");
        }
    }

    @Override
    public void delete(Integer id) {
        int res = workQualityStatisticsMapper.delete(id);
        if (res == 0) {
            throw new WorkQualityStatisticsException("Delete WorkQualityStatistics failed");
        }
    }

    @Override
    public WorkQualityStatistics getOne(Integer id) {
        WorkQualityStatistics workQualityStatistics = workQualityStatisticsMapper.getOne(id);
        if (workQualityStatistics == null) {
            throw new WorkQualityStatisticsException("Requested WorkQualityStatistics does not exist");
        }
        return workQualityStatistics;
    }

    @Override
    public List<WorkQualityStatistics> getAll() {
        return workQualityStatisticsMapper.getAll();
    }
}
